package com.shangxia.monomer.study.thread.base.util;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @ProjectName: monomer
 * @ClassName: CountDownLatchDemo
 * @Time: 2021/10/1
 * @Author: zhouy
 * @Description:
 * @Experience:
 */

@Slf4j
public class CountDownLatchDemo {

    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 1; i <= 6; i++) {
            final int temp = i;
            new Thread(() -> {
                System.out.println(temp + "离开教室");
                countDownLatch.countDown(); //计数器 减一
            }, "" + i).start();
        }

        try {
            countDownLatch.await(); // 计数器到 0 向下执行
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("都出去了，关门");

    }


}
